package com.hitrust.gs.dao;

import java.util.ArrayList;

import com.hitrust.gs.bean.GSWarehouseStorageConfigBean;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.db.GSBaseDAO;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.ProductMapOldVO;
import com.hitrust.gs.vo.ProductUpdatePicVO;
import com.hitrust.gs.vo.WarehouseMaxStorageCofigVO;


/**
 * @author wuyang
 *
 */
public class GSWarehouseStorageConfigDAO extends GSBaseDAO
{
   
      
    /**
     * 查询仓库执行配置
     * @param warehouseCode         客修分公司编码
     * @return                      仓库执行配置对象
     * @throws GSException
     */
    public GSWarehouseStorageConfigBean getWarehouseStorageConfig(String warehouseCode) throws GSException { 
		String tSql = "select * from t_warehouse_storage_config where warehouse_code = ?";
		ArrayList tList = null;
		GSWarehouseStorageConfigBean bean = null;
		Object[] tObj = {warehouseCode};
		try{
			tList = this.executeQuery(new GSWarehouseStorageConfigBean(),tSql,tObj);
			if(tList.size() >0){
				bean = (GSWarehouseStorageConfigBean)tList.get(0);
			}else{
//				throw new GSException(GSException.BME20041,GSException.BME20041_MSG);
			}
		}catch(Exception e){
			GSLogWriter.error(this,e.toString());
			throw new GSException(GSException.E19999,GSException.E19999_MSG);
		}
		
		return bean;
    } 
      
    
    
    /**
     * 添加仓库执行配置
     * 
     * @param 客修分公司编码， 状态
     * 
     * @return boolean
     */
    public boolean insertWarehouseStorageConfig(String warehouseCode,String status) throws GSException {
        boolean bl = false;
        String tSql = "insert into t_warehouse_storage_config values (S_WAREHOUSE_STORAGE_CONFIG.nextval,'"+warehouseCode+"',"+status+")";
        try {
                bl = this.executeUpdate(tSql, null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }    
        return bl;
    }
    
    
    
    /**
     * 修改仓库执行配置
     * 
     * @param 客修分公司编码， 状态
     * 
     * @return boolean
     */
    public boolean updateWarehouseStorageConfig(String warehouseCode,String status) throws GSException {
        boolean bl = false;
        String tSql = "update t_warehouse_storage_config set status = "+status+" where warehouse_code = '"+warehouseCode+"'";         
        try {
                bl = this.executeUpdate(tSql, null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }
        return bl;
    }
    
    
    
    
    /**
     * 添加仓库产品最高库存设置
     * 
     * @param 最高库存设置对象
     * 
     * @return boolean
     */
    public boolean insertWarehouseMaxStorageConfig(WarehouseMaxStorageCofigVO vo) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" insert into t_warehouse_max_storage_config(id, warehouse_code, product_code, max_count, status, " +
        		  "create_user, carete_user_id, create_time) values ( ");
        sb.append(" S_WAREHOUSE_MAX_STORAGE_CONFIG.nextval, ");
        sb.append("'"+vo.getWarehouse_code()+"',");
        sb.append("'"+vo.getProduct_code()+"',");
        sb.append( vo.getMax_count()+",");
        sb.append("'"+vo.getStatus()+"',");
        sb.append("'"+vo.getCreate_user()+"',");
        sb.append("'"+vo.getCarete_user_id()+"',");
        sb.append("'"+vo.getCreate_time()+"'");
        sb.append(")");
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }    
        return bl;
    }
     
    /**
     * 修改仓库产品最高库存设置
     * 
     * @param 最高库存设置对象
     * 
     * @return boolean
     */
    public boolean updateWarehouseMaxStorageConfig(WarehouseMaxStorageCofigVO vo) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" update t_warehouse_max_storage_config set ");
        sb.append(" max_count = '"+vo.getMax_count()+"',");
        sb.append(" status = '"+vo.getStatus()+"',");
        sb.append(" last_update_user = '"+vo.getLast_update_user()+"',");
        sb.append(" last_update_user_id = '"+vo.getLast_update_user_id()+"',");
        sb.append(" last_update_time = '"+vo.getLast_update_time()+"'");
        sb.append(" where ");
        sb.append(" warehouse_code = '"+vo.getWarehouse_code()+"'");
        sb.append(" and product_code = '"+vo.getProduct_code()+"'");
             
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }
        return bl;
    }
    
    /**
     * 导入数据到老库存产品对应表
     * 
     * @param ProductUpdatePicVO
     * 
     * @return boolean
     */
    public boolean insertProductMapOld(ProductMapOldVO vo) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" insert into T_PRODUCT_MAP_OLD values (" );
        sb.append(" sys_guid(), ");
        sb.append("'"+vo.getProduct_code()+"',");
        sb.append("'"+vo.getProduct_code_map()+"',");
        sb.append("'"+vo.getWarehouse_code()+"',");
        sb.append("'"+vo.getLast_update_time()+"'");
        sb.append(")");
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }    
        return bl;
    }
    
    /**
     * 导入数据到不可采购仍然可以出库配置执行表
     * 
     * @param ProductUpdatePicVO
     * 
     * @return boolean
     */
    public boolean insertProductUpdatePic(ProductUpdatePicVO vo) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" insert into T_PRODUCT_UPDATE_PIC(id, PRODUCT_ID, CONCENTRICITY_CODE, PIC, CREATE_USER_ID, " +
        		  "CREATE_USER, CREATE_TIME, ENABLED_TIME,status,AUDITING_STATUS) values ( ");
        sb.append(" S_PRODUCT_UPDATE_PIC.nextval, ");
        sb.append("'"+vo.getProduct_id()+"',");
        sb.append("'"+vo.getConcentricity_code()+"',");
        sb.append( vo.getPic()+",");
        sb.append("'"+vo.getCreate_user_id()+"',");
        sb.append("'"+vo.getCreate_user()+"',");
        sb.append("'"+vo.getCreate_time()+"',");
        sb.append("'"+vo.getEnabled_time()+"',");
        sb.append("'"+vo.getStatus()+"',");
        sb.append("'"+vo.getAuditing_status()+"'");
        sb.append(")");
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }    
        return bl;
    }
    
    /**
     * 修改数据到不可采购仍然可以出库配置执行表
     * 
     * @param ProductUpdatePicVO
     * 
     * @return boolean
     */
    public boolean updateProductUpdatePic(ProductUpdatePicVO vo) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" update T_PRODUCT_UPDATE_PIC set ");
        sb.append(" PRODUCT_ID = '"+vo.getProduct_id()+"',");
        sb.append(" PIC = '"+vo.getPic()+"',");
        sb.append(" CREATE_USER_ID = '"+vo.getCreate_user_id()+"',");
        sb.append(" CREATE_USER = '"+vo.getCreate_user()+"',");
        sb.append(" CREATE_TIME = '"+vo.getCreate_time()+"'");
        sb.append(" ENABLED_TIME = '"+vo.getEnabled_time()+"'");
        sb.append(" where ");
        sb.append(" CONCENTRICITY_CODE = '"+vo.getConcentricity_code()+"'");
        
             
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }
        return bl;
    }
    
    
    /**
     * 审批通过
     * 
     * @param ProductUpdatePicVO
     * 
     * @return boolean
     */
    public boolean passProductUpdatePic(String id,String userName,String userId,String currTime) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" update T_PRODUCT_UPDATE_PIC set ");
        sb.append(" AUDITING_STATUS = '1',");
        sb.append(" AUDITING_USER_ID = '"+userId+"',");
        sb.append(" AUDITING_USER = '"+userName+"',");
        sb.append(" AUDITING_TIME = '"+currTime+"'");
        sb.append(" where ");
        sb.append(" id = '"+id+"'");
        
             
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }
        return bl;
    }
    
    
    /**
     * 审批不通过
     * 
     * @param ProductUpdatePicVO
     * 
     * @return boolean
     */
    public boolean noPassProductUpdatePic(String id,String userName,String userId,String currTime) throws GSException {
        boolean bl = false;
        StringBuffer sb = new StringBuffer();
        sb.append(" update T_PRODUCT_UPDATE_PIC set ");
        sb.append(" AUDITING_STATUS = '2',");
        sb.append(" AUDITING_USER_ID = '"+userId+"',");
        sb.append(" AUDITING_USER = '"+userName+"',");
        sb.append(" AUDITING_TIME = '"+currTime+"'");
        sb.append(" where ");
        sb.append(" id = '"+id+"'");
        
             
        try {
                bl = this.executeUpdate(sb.toString(), null, null, "");
            } catch (Exception e) {
                throw new GSException(GSException.E20042, GSException.E20042_MSG);
            }
        return bl;
    }
}
